import re
from collections import defaultdict


def process_log_files(file_paths):
    pattern = re.compile(
        r'(\d+):(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+) \| INFO  \| TID:(\d+) \| .+ \| (.+) \| (.+): (\d+) 毫秒')
    logs = defaultdict(dict)

    for file_path in file_paths:
        with open(file_path, 'r', encoding='utf-8') as file:
            for line in file:
                match = pattern.match(line)
                if match:
                    _, _, tid, _, description, time = match.groups()
                    logs[tid][description] = int(time)

    return logs


def format_output(logs):
    for tid, data in logs.items():
        print(f"Processing TID: {tid}")
        if '语音转文本接口响应时间' in data:
            print(f"1. 语音转文本接口响应时间: {data['语音转文本接口响应时间']} 毫秒")

        if '大模型对练响应总时长时间' in data:
            print(f"2. 大模型对练响应总时长时间: {data['大模型对练响应总时长时间']} 毫秒")

        if '模型对练接口响应时间' in data:
            print(f"2.1 模型对练接口响应时间: {data['模型对练接口响应时间']} 毫秒")

        if '文本转语音接口响应时间' in data:
            print(f"2.2 文本转语音接口响应时间: {data['文本转语音接口响应时间']} 毫秒")

        print()  # 为不同的TID之间添加空行


# 使用示例
file_paths = ['log1.txt', 'log2.txt', 'log3.txt', 'log4.txt']   # 替换为实际的文件路径
logs = process_log_files(file_paths)
format_output(logs)